package com.jeff.tianti.cms.dao;

import com.jeff.tianti.cms.dto.font.ConsultComplianceTo;
import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jeff.tianti.cms.entity.ConsultCompliance;
import com.jeff.tianti.cms.dto.ConsultComplianceQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xujianfang
 * @desc ConsultComplianceDaoImpl��
 * @date 2019-07-03
 */

public class ConsultComplianceDaoImpl extends CustomBaseSqlDaoImpl implements ConsultComplianceDaoCustom {

    public PageModel<ConsultCompliance> queryConsultCompliancePage(ConsultComplianceQueryDTO consultComplianceQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append(" select t from ConsultCompliance t where 1=1 ");
        if (consultComplianceQueryDTO != null) {
            String state = consultComplianceQueryDTO.getState();
            if (StringUtils.isNotBlank(state) && !"-1".equals(state)) {
                hql.append(" and t.state = :state ");
                map.put("state", state);
            }
        }
        return this.queryForPageWithParams(hql.toString(), map, consultComplianceQueryDTO.getCurrentPage(), consultComplianceQueryDTO.getPageSize());
    }

    public List<ConsultCompliance> queryConsultComplianceList(ConsultComplianceQueryDTO consultComplianceQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from ConsultCompliance t ");
        return this.queryByMapParams(hql.toString(), map);
    }

    @Override
    public PageModel<ConsultCompliance> queryConsultCompliancePages(ConsultComplianceTo consultComplianceTo) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append(" select t from ConsultCompliance t where 1=1 ");
        if (consultComplianceTo != null) {
            String number = consultComplianceTo.getNumber();
            if (StringUtils.isNotBlank(number)) {
                hql.append(" and t.number like :number ");
                map.put("number", "%"+number+"%");
            }
            String industry = consultComplianceTo.getIndustry();
            if (StringUtils.isNotBlank(industry)) {
                hql.append(" and t.industry like :industry ");
                map.put("industry", "%"+industry+"%");
            }
            String uid = consultComplianceTo.getUid();
            if (StringUtils.isNotBlank(uid)) {
                hql.append(" and t.uid = :uid ");
                map.put("uid", uid);
            }
            String state = consultComplianceTo.getState();
            if (StringUtils.isNotBlank(state)) {
                hql.append(" and t.state = :state ");
                map.put("state", state);
            }
        }
        return this.queryForPageWithParams(hql.toString(), map, consultComplianceTo.getCurrentPage()+1, consultComplianceTo.getPageSize());
    }


}